package com.dongge.entity;

import org.hibernate.annotations.*;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2015/11/3.
 */
@Entity
@Table
public class Department implements Serializable{
    private Long id;
    private String name;
    private Department parent ;
    private Set<Department> departments = new HashSet<Department>();


    public Department() {
//        this.id = (long)0;
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne
    @JoinColumn(name = "parentId")
//    @Cascade({CascadeType.ALL})
    public Department getParent() {
        return parent;
    }

    public void setParent(Department parent) {
        this.parent = parent;
    }

//    @OneToMany(mappedBy = "parent")
    @OneToMany
    @JoinColumn(name = "parentId",referencedColumnName = "parentId")
    @Cascade({CascadeType.SAVE_UPDATE})
    public Set<Department> getDepartments() {
        return departments;
    }

    public void setDepartments(Set<Department> departments) {
        this.departments = departments;
    }
}
